<template>
  <div class="body">
    <!-- 收货地址 -->
    <div class="selectAddress">
      选择收货地址：
      <el-select v-model="consignee" placeholder="请选择" style="width: 1120px">
        <el-option
          v-for="item in options"
          :key="item.id"
          :label="item.username + ' ' + item.address"
          :value="item.username + ' ' + item.address"
        >
        </el-option>
      </el-select>
    </div>
    <!-- 列表框 -->
    <div class="orderlist">
      <div class="list-ul">
        <ul class="udiv">
          <div class="uli-left">
            <div class="checkorder">确认订单信息</div>
            <div class="orderdetail">商品信息</div>
          </div>
          <div class="uli-right">
            <div>单价</div>
            <div>数量</div>
            <div>小计</div>
          </div>
        </ul>
      </div>
    </div>

    <!-- 商品列表 -->
    <div class="order-goods" v-for="brand in goods" :key="brand.id">
      <div class="order-Shop">
        <div class="shop">{{ brand.shop }}</div>
      </div>
      <div class="goods" v-for="item in brand.commodity" :key="item.id">
        <div class="list">
          <div class="image">
            <el-image :src="item.src" style="width: 110px; height: 100px">
            </el-image>
          </div>
          <div class="detail">
            <el-link href="/" :underline="false">{{ item.detail }}</el-link>
          </div>
        </div>
        <div class="right">
          <div class="price">
            <span>{{ item.price }}</span>
          </div>
          <div class="amount">
            {{ item.amount }}
          </div>
          <div class="money">
            <span>{{ (item.amount * item.price) | getmoney }}</span>
          </div>
        </div>
      </div>
    </div>

    <!-- 支付信息 -->
    <div class="payInfo">
      <div class="box-card">
        <div class="paymoney">
          实付款：
          <div class="moneys">{{ getPrice | getmoney }}</div>
        </div>
        <div class="address">寄送至：{{ getConsignee[1] }}</div>
        <div class="username">收货人：{{ getConsignee[0] }}</div>
      </div>
      <div class="orderButton">
        <el-button
          type="text"
          class="goCart"
          icon="el-icon-back"
          size="medium"
          @click="goCart"
          >返回购物车</el-button
        >
        <el-button
          type="text"
          class="submitOrder"
          style="color: #fff"
          @click="submitOrder"
          >提交订单</el-button
        >
      </div>
    </div>

    <!-- 支付弹窗 -->
    <div>
      <Pay :dialog="dialog" @dialogEvt="handelDialog" @buy="handelbuyClick" />
    </div>
  </div>
</template>

<script>
import Pay from './pay.vue'
export default {
  components: {
    Pay
  },
  data () {
    return {
      dialog: false,
      options: [],
      consignee: '',
      goods: [
        {
          id: 1,
          shop: '花漫里',
          commodity: [
            {
              id: 1,
              src: 'https://img13.360buyimg.com/n0/s80x80_jfs/t1/115111/20/13000/95318/5f12e816Eb41dbb30/51f5b2be51425a98.jpg.dpg',
              detail:
                '道袍男装中国风套装潮流汉服夏季唐装古风服装网红衣服古装三件套 黑色群鹤外搭+内搭黑L 建议100斤至128斤',
              price: '179',
              amount: 1,
              money: '179'
            }
          ]
        }
      ]
    }
  },
  mounted () {
    console.log(this.$store.state.user.consignees)
    this.options = this.$store.state.user.consignees
  },
  filters: {
    getmoney (val) {
      return '￥' + val.toFixed(2)
    }
  },
  methods: {
    goCart () {
      this.$router.push('/shoppingcart')
    },
    submitOrder () {
      this.dialog = true
    },
    handleAmount () {},
    handelDialog (data) {
      this.dialog = data
    },
    // 确定购买（提交表单）
    handelbuyClick (payname) {
      console.log(payname)
    }
  },
  computed: {
    getPrice () {
      let sumMoney = 0
      this.goods.forEach((item) => {
        console.log(item)
        item.commodity.forEach((it) => {
          sumMoney += parseFloat(it.money)
        })
      })
      console.log(sumMoney)
      return sumMoney
    },
    getConsignee () {
      // console.log(this.consignee.split(' '))
      return this.consignee.split(' ')
    }
  }
}
</script>

<style lang="scss" scoped>
.body {
  // border: 1px solid #ccc;
  width: 1250px;
  .selectAddress {
    // border: 1px solid;
    margin-top: 10px;
    margin-left: 5px;
    text-align: center;
    // height: 250px;
  }
  .orderlist {
    display: flex;
    margin-top: 20px;
    background-color: #f3f3f3;
    border: 1px solid #ccc;
    .list-ul {
      display: flex;
      line-height: 40px;
      width: 100%;
      .udiv {
        display: flex;
        list-style: none;
        width: 100%;
        justify-content: space-between;
        .uli-left {
          display: flex;
          .checkorder {
            text-align: center;
            width: 100px;
            margin-left: 10px;
          }
          .orderdetail {
            text-align: center;
            width: 480px;
          }
        }
        .uli-right {
          display: flex;
        }
        .uli-right div {
          width: 220px;
          text-align: center;
        }
      }
    }
  }
}
</style>

<style lang="scss" scoped>
.order-goods {
  border: 1px solid #ccc;
  margin-bottom: 20px;
  margin-top: 5px;
  .el-link:hover {
    color: #e2231a;
  }
  .order-Shop {
    background-color: #f3f3f3;
    height: 35px;
    display: flex;
    .shop {
      margin-left: 60px;
      font-size: 15px;
      padding-top: 6px;
      text-align: center;
    }
  }
  .goods {
    display: flex;
    // border: 1px solid #ccc;
    .list {
      display: flex;
      line-height: 40px;
      margin-left: 50px;
      .image {
        margin-top: 10px;
      }
      .detail {
        width: 400px;
        text-align: center;
      }
    }
    .right {
      display: flex;
      line-height: 40px;
      .price {
        width: 260px;
        text-align: center;
        // color: #e4393c;
      }
      .amount {
        width: 200px;
        text-align: center;
      }
      .money {
        width: 220px;
        text-align: center;
        color: #e4393c;
      }
    }
  }
}
</style>

<style lang="scss" scoped>
.payInfo {
  // border: 1px solid;
  height: 300px;
  .box-card {
    width: 480px;
    height: 150px;
    // display: flex;
    margin-left: 765px;
    border: 1px solid;
    .paymoney {
      // width: 145px;
      display: flex;
      margin: 20px 0px 0px 30px;
      .moneys {
        color: #e4393c;
      }
    }
    .address {
      margin: 20px 0px 0px 30px;
    }
    .username {
      margin: 20px 0px 0px 30px;
    }
  }
  .orderButton {
    display: flex;
    float: right;
    margin-top: 5px;
    margin-right: 5px;
    .goCart {
      margin-right: 30px;
    }
    .submitOrder {
      background-color: #e4393c;
      width: 182px;
      height: 39px;
      font-size: 14px;
    }
  }
}
</style>
